<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets">          

    <ui:composition template="templatePadrao.xhtml"> 
                
            <ui:define name="top">       
                <ui:include src="menu.xhtml" />
            </ui:define>        
        
   <ui:define name="content">

       <h:form id="formMessages">
           <p:growl id="messages" widgetVar="messages" showDetail="true" life="5000" sticky="false" autoUpdate="true" />  
       </h:form>
       
       <h:form id="principal" prependId="false">
           
                <p:contextMenu for="turmas">                      
                     <p:menuitem value="Deletar" update="turmas" icon="ui-icon-close" onclick="confirmation.show()"/>  
                     <p:menuitem value="Editar"  update="principal" icon="ui-icon-arrowrefresh-1-w" actionListener="#{TurmaController.preparaEdicao()}"/>
                </p:contextMenu>  
           
           <p:fieldset legend="Turma">                                    

               <table width="100%" border="0">
                           <tr>
                               <td width="20px">
                                    <p:outputLabel>Código Turma *</p:outputLabel>
                               </td>
                               <td>
                                    <p:inputText id="codigo_turma"  size="16" maxlength="16" value="#{TurmaController.turma.codigo}" title="Informe o Código" />                                        
                               </td>
                               <td>
                                    <p:outputLabel>Nome *</p:outputLabel>
                               </td>
                               <td>
                                    <p:inputText id="nome_turma"  size="60" maxlength="60" value="#{TurmaController.turma.nome}" title="Informe o Nome" />               
                               </td>
                           </tr>
                           <tr>                               
                               <td>
                                    <p:selectOneMenu label="Unidades" id="selectTipologia" value="#{TurmaController.selectedUnidade}">                                    
                                          <f:selectItems value="#{TurmaController.carregarSelect}" />
                                    </p:selectOneMenu>                            
                               </td>
                               <td>
                                   <p:commandButton value="Aulas" actionListener="#{TurmaController.resetTurmaAula}" onclick="turmaAula.show()" update=":dlgDisciplina :dlgDisciplina:aulas"/>
                                       
                               </td>
                               
                               <td>                                   
                                   <p:selectOneMenu onchange="escondeValorTurma()" style="width: 150px;" label="Forma de Cálculo" id="selectFormCalc" value="#{TurmaController.selectedFormaCalc}">
                                       <p:ajax event="change" />                                       
                                       <f:selectItem itemLabel="Padrão" itemValue="1"/>
                                       <f:selectItem itemLabel="Percentual" itemValue="2"/>
                                       <f:selectItem itemLabel="Valor Fixo" itemValue="3"/>
                                   </p:selectOneMenu>
                               </td>
                               <td>
                                   <p:inputText id="valorTurma" size="15" maxlength="15" title="Informe o valor" onkeyup="mascara(this, valor);" value="#{TurmaController.turma.valor}">
                                        <f:convertNumber pattern="#,##0.00"/>
                                    </p:inputText>                                   
                               </td>                               
                               
                           </tr>
                         </table>                                          
               
                    <p:commandButton value="Salvar" id="salvaTurma" update="turmas :principal" actionListener="#{TurmaController.preparaInclusao()}"/>
                    <p:commandButton value="Cancelar" id="cancelarTurma" process="@form" update=":principal" actionListener="#{TurmaController.resetTurma()}"/>
               
           </p:fieldset>
           
     <p:dataTable id="turmas" var="turma" emptyMessage="Não existem Turmas cadastradas" 
                  value="#{TurmaController.lista}" rowKey="#{turma.id}" 
                  selectionMode="single" selection="#{TurmaController.turmaSelecionada}" 
                  paginator="true" rows="10">
     
                    <p:column filterMatchMode="contains" filterBy="#{turma.codigo}">   
                        <f:facet name="header">  
                                <h:outputText value="Código" />  
                        </f:facet>                        
                            <h:outputText value="#{turma.codigo}"/>
                    </p:column>      
         
                    <p:column filterMatchMode="contains" filterBy="#{turma.nome}">   
                        <f:facet name="header">  
                                <h:outputText value="Nome" />  
                        </f:facet>                        
                            <h:outputText value="#{turma.nome}"/>
                    </p:column>               
         
     </p:dataTable>
           
           <p:commandButton value="Deletar" id="deletarTurma" update="turmas :principal" onclick="confirmation.show()"/>
           <p:commandButton value="Editar"  id="editarTurma"  update="principal" actionListener="#{TurmaController.preparaEdicao()}"/>
           
   </h:form>
       
        <!-- Abaixo temos um modal de confirmação de exclusão repare que ele é fora do form principal, pois se colocarmos dentro podemos ter alguns problemas com isso.-->
        <h:form id="dlg" prependId="false">
            <p:confirmDialog message="Deseja realmente excluir este registro?" header="Aviso" severity="alert" widgetVar="confirmation" modal="true">
                <!--caso seja sim chamo o metodo excluir, e fecho o modal com o oncomplete, tenho o process que estou dizendo para processar o form, e update para atualizar a tabela-->
                <p:commandButton id="btnSim" value="Sim" oncomplete="confirmation.hide();" actionListener="#{TurmaController.deleteTurma()}" process="@form" update=":principal" />
                <!--caso seja não somente fecha o modal-->
                <p:commandButton id="btnNao" value="Não" onclick="confirmation.hide();" type="button"/>
            </p:confirmDialog>
        </h:form>                  
            
            <p:dialog widgetVar="turmaAula" id="dialogAula" header="Aulas" resizable="false" closeOnEscape="true">                                

                <h:form id="dlgDisciplina" prependId="false">
                
                <table>
                    
                    <tr>
                        <td>
                            <p:selectOneMenu style="width: 300px;" label="Disciplina" id="selectDisciplina" value="#{TurmaController.selectedDisciplina}">
                                <p:ajax event="change" update="selectProfessor"/>
                                  <f:selectItems value="#{TurmaController.carregarSelectDisciplina}" />
                            </p:selectOneMenu>
                        </td>
                        <td>              
                            <p:selectOneMenu style="width: 300px;" label="Professor" id="selectProfessor" value="#{TurmaController.selectedProfessor}">
                                <p:ajax event="change" update="selectDisciplina"/>
                                  <f:selectItems value="#{TurmaController.carregarSelectProfessor}" />
                            </p:selectOneMenu>                            
                        </td>
                        <td>
                            <p:commandButton icon="ui-icon-search" title="Consulta Disponibilidade" actionListener="#{TurmaController.exibeDisponibilidade()}" process="@form" update=":dlgDisponibilidade"/> 
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <p:selectOneMenu style="width: 300px;" label="Dia da Semana" id="selectDia" value="#{TurmaController.selectedDiaSemana}"> 
                                <f:selectItems value="#{TurmaController.carregarDiaSemana}" />
                             </p:selectOneMenu> 
                        </td>
                        <td>
                            <p:selectOneMenu style="width: 300px;" label="Sala de Aula" id="selectSala" value="#{TurmaController.selectedSala}"> 
                                <f:selectItems value="#{TurmaController.carregarSelectSala}" />
                             </p:selectOneMenu>                            
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <p:selectOneMenu style="width: 300px;" label="Buscar Material" id="selectMaterial" value="#{TurmaController.selectedMaterial}"> 
                                <f:selectItem itemLabel="Buscar Material?" itemValue=""/>
                                <f:selectItem itemLabel="Sim" itemValue="sim"/>
                                <f:selectItem itemLabel="Não" itemValue="nao"/>
                             </p:selectOneMenu>                                                        
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <h:outputLabel value="Hora Início :   " style="left:0px;"/>                                                         
                            <p:inputMask mask="99:99" size="5" id="horaIniDisciplina" value="#{TurmaController.horaIni}" title="Informe a hora inicial da aula" onblur="Verifica_Hora_Ini(this)" /> 

                            <h:outputLabel value="Hora Fim:   " style="left:0px;"/>                                                         
                            <p:inputMask mask="99:99" size="5" id="horaFimDisciplina" value="#{TurmaController.horaFim}" title="Informe a hora final da aula"  onblur="Verifica_Hora_Fim(this)"/> 
                        </td>                        
                    </tr>
                </table>                
                
                <p:commandButton value="Salvar" id="incluiDisplinaProfessor" update=":dlgDisciplina dlgDisciplina:aulas" actionListener="#{TurmaController.preparaInclusaoAula()}"/>
                <p:commandButton value="Cancelar" id="cancelarDisplinaProfessor"  actionListener="#{TurmaController.resetTurmaAula}" onclick="turmaAula.hide()"/>
                
                <p:dataTable id="aulas" var="aula" emptyMessage="Não existem aulas cadastradas" 
                             value="#{TurmaController.listaAula}" rowKey="#{aula.id}" 
                             selectionMode="single" selection="#{TurmaController.aulaSelecionada}" 
                             paginator="true" rows="10">                
                    
                               <p:column>   
                                   <f:facet name="header">  
                                           <h:outputText value="Disciplina" />  
                                   </f:facet>                        
                                       <h:outputText value="#{aula.disciplina.nome}"/>
                               </p:column>      

                               <p:column>   
                                   <f:facet name="header">  
                                           <h:outputText value="Professor" />  
                                   </f:facet>                        
                                       <h:outputText value="#{aula.professor.nome}"/>
                               </p:column> 
                    
                               <p:column>   
                                   <f:facet name="header">  
                                           <h:outputText value="Dia da Semana" />  
                                   </f:facet>                        
                                       <h:outputText value="#{aula.diaSemana.nome}"/>
                               </p:column>  
                    
                               <p:column>   
                                   <f:facet name="header">  
                                           <h:outputText value="Sala" />  
                                   </f:facet>                        
                                       <h:outputText value="#{aula.sala.nome}">                                           
                                       </h:outputText>
                               </p:column>                    
                    
                               <p:column>   
                                   <f:facet name="header">  
                                           <h:outputText value="Hora Início" />  
                                   </f:facet>                        
                                       <h:outputText value="#{aula.horaIni}">
                                           <f:convertDateTime timeZone="America/Sao_Paulo" pattern="HH:mm"/>
                                       </h:outputText>
                               </p:column>     
                    
                               <p:column>   
                                   <f:facet name="header">  
                                           <h:outputText value="Hora Fim" />  
                                   </f:facet>                        
                                       <h:outputText value="#{aula.horaFim}">
                                           <f:convertDateTime timeZone="America/Sao_Paulo" pattern="HH:mm"/>
                                       </h:outputText>
                               </p:column>       
                    
                               <p:column>   
                                   <f:facet name="header">  
                                           <h:outputText value="Material?" />  
                                   </f:facet>                        
                                       <h:outputText value="#{aula.material}"/>                                                                                  
                               </p:column>                    

                </p:dataTable>                
                
           <p:commandButton value="Deletar" id="deletarAula" update=":dlgDisciplina :dlgDisciplina:aulas" actionListener="#{TurmaController.deleteAula()}" />
           <p:commandButton value="Editar"  id="editarAula"  update=":dlgDisciplina" actionListener="#{TurmaController.preparaEdicaoAula()}"/>                
           
           <h:panelGrid>  
                    <p:panel header="Exportar Dados">  
                        <h:commandLink>  
                            <p:graphicImage value="./../img/excel.png" />  
                            <p:dataExporter type="xls" target="aulas" fileName="Aulas" />  
                        </h:commandLink>  

                        <h:commandLink>  
                            <p:graphicImage value="./../img/pdf.png" />  
                            <p:dataExporter type="pdf" target="aulas" fileName="Aulas" encoding="iso-8859-1"/>  
                        </h:commandLink>  

                    </p:panel>  
                </h:panelGrid>                      
                
           </h:form>
           
       </p:dialog> 
        
        <!-- Abaixo temos o modal que irá controlar as horas contratadas do professor-->
        <p:dialog widgetVar="disponibilidade" id="dialogDisponibilidade" header="Carga fechada - Horas Contratadas" resizable="false" closeOnEscape="true">                                
       
            <h:form id="dlgDisponibilidade" prependId="false">
                
                <p:dataTable id="disponibilidades" var="disponibilidade" emptyMessage="Não existe disponibilidade cadastrada" 
                             value="#{TurmaController.listaDisponibilidade}" rowKey="#{disponibilidade.id}" 
                             paginator="true" rows="10">       
                    
                               <p:column>   
                                   <f:facet name="header">  
                                           <h:outputText value="Dia da Semana" />  
                                   </f:facet>                        
                                       <h:outputText value="#{disponibilidade.diaSemana.nome}"/>
                               </p:column> 
                    
                               <p:column>   
                                   <f:facet name="header">  
                                           <h:outputText value="Contrato" />  
                                   </f:facet>                        
                                       <h:outputText value="#{disponibilidade.tipoContrato.descricao}"/>
                               </p:column>                      
                    
                               <p:column>   
                                   <f:facet name="header">  
                                           <h:outputText value="Hora Inicial" />  
                                   </f:facet>                        
                                       <h:outputText value="#{disponibilidade.hora_ini}">
                                           <f:convertDateTime timeZone="America/Sao_Paulo" pattern="HH:mm"/>
                                       </h:outputText>
                               </p:column>     
                    
                               <p:column>   
                                   <f:facet name="header">  
                                           <h:outputText value="Hora Final" />  
                                   </f:facet>                        
                                       <h:outputText value="#{disponibilidade.hora_fim}">
                                           <f:convertDateTime timeZone="America/Sao_Paulo" pattern="HH:mm"/>
                                       </h:outputText>
                               </p:column>                    
                    
                </p:dataTable>
                
            </h:form>
            
        </p:dialog>   
    <h:outputScript library="js" name="CadastroTurma.js"/>
   </ui:define>
        
    </ui:composition>        
    
</html>